package com.dimong.www.loan.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.dimong.loan.sdk.utils.UIUtils;
import com.dimong.www.loan.R;

public class SettingDialog extends Dialog implements View.OnClickListener {
    private Activity activity;

    private TextView tv_dialog_title;
    private TextView tv_dialog_desc;
    private TextView tv_dialog_cancel;
    private TextView tv_dialog_ok;
    private View ll_select;
    private View view_select_line;
    private SettingDialogInterface settingDialogInterface;
    private String title;
    private String desc;
    private String[] btns;

    public SettingDialog(Activity activity, String title, String desc, String[] btns) {
        super(activity, R.style.MyDialog);
        this.activity = activity;

        this.title = title;
        this.desc = desc;
        this.btns = btns;
    }

    public void setSettingDialogInterface(SettingDialogInterface settingDialogInterface) {
        this.settingDialogInterface = settingDialogInterface;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_setting);
        initView();
        setViewStatus();
        this.setCanceledOnTouchOutside(false);
    }

    private void initView() {
        ll_select = findViewById(R.id.ll_select);
        view_select_line = findViewById(R.id.view_select_line);
        tv_dialog_title = findViewById(R.id.tv_dialog_title);
        tv_dialog_desc = findViewById(R.id.tv_dialog_desc);
        tv_dialog_cancel = findViewById(R.id.tv_dialog_cancel);
        tv_dialog_ok = findViewById(R.id.tv_dialog_ok);

        if (btns == null || btns.length == 0) {
            ll_select.setVisibility(View.GONE);
        }else if(btns.length == 1){
            ll_select.setVisibility(View.VISIBLE);
            tv_dialog_cancel.setVisibility(View.VISIBLE);
            view_select_line.setVisibility(View.GONE);
            tv_dialog_ok.setVisibility(View.GONE);
            tv_dialog_cancel.setText(btns[0]);
        }else {
            ll_select.setVisibility(View.VISIBLE);
            tv_dialog_cancel.setVisibility(View.VISIBLE);
            view_select_line.setVisibility(View.VISIBLE);
            tv_dialog_ok.setVisibility(View.VISIBLE);
            tv_dialog_cancel.setText(btns[0]);
            tv_dialog_ok.setText(btns[1]);
        }
    }

    private void setViewStatus() {
        tv_dialog_title.setText(title);
        tv_dialog_desc.setText(desc);
        tv_dialog_cancel.setOnClickListener(this);
        tv_dialog_ok.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_dialog_cancel:
                if (settingDialogInterface != null) {
                    settingDialogInterface.onCancelClick();
                }
                break;
            case R.id.tv_dialog_ok:
                if (settingDialogInterface != null) {
                    settingDialogInterface.onOkClick();
                }
                break;
        }
    }

    public interface SettingDialogInterface {
        void onCancelClick();

        void onOkClick();
    }
}
